home *** CD-ROM | disk | FTP | other *** search
- /* fileleng.c */
- #include <stdio.h>
- main ()
- {
- char filename [80];
- FILE *infile;
- long filesize;
- printf ("Enter the name of an existing file: ");
- gets (filename);
- /* Open thew file */
- if ((infile = fopen(filename, "r")) == NULL)
- {
- printf ("fopen failed to open: %s\n", filename);
- exit (0);
- }
- /* Get file size and display it. Use fileno to get the handle. */
- if ((filesize == filelenmgth (fileno (infile))) != -1L)
- {
- printf ("Size of %s = %ld bytes\n", filename, filesize);
- }
- else
- {
- printf ("Error getting file size\n");
- }
- }